<template>
  <div class="photo-info">
    <!-- 面板 -->
    <van-panel :desc="info.add_time">
      <template #header>
        <div class="my-header">
          <h1>{{info.title}}</h1>
          <span>阅读{{info.click}}</span>
        </div>
      </template>
      <div class="img-box">
        <img
          v-for="(item,index) in thums"
          :key="item.id"
          :src="item.src"
          alt=""
          @click="showThum(index)"
        >
      </div>
      <div class="content">{{info.content}}</div>
    </van-panel>
    <Comment :id="id"></Comment>
  </div>
</template>
<script>
import Comment from '@/components/Comment'
import { ImagePreview } from 'vant'
export default {
  name: 'PhotoInfo',
  props: ['id'],
  data: () => ({
    info: {},
    thums: []
  }),
  created() {
    this.getImageInfoById()
    this.getThumImages()
  },
  methods: {
    async getImageInfoById() {
      const res = await this.$http.getImageInfoById(this.id)
      // console.log(res)
      this.info = res.message
    },
    async getThumImages() {
      const res = await this.$http.getThumImages(this.id)
      this.thums = res.message
    },
    showThum(startPosition) {
      const images = []
      // 过滤得到需要的数组
      this.thums.forEach(item => {
        if (item.src) images.push(item.src)
      })
      ImagePreview({
        images,
        startPosition
      })
    }
  },
  components: {
    Comment
  }
}
</script>
<style lang="less" scoped>
.photo-info {
  padding: 0 10px;
  .my-header {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    h1 {
      font-size: 14px;
      padding: 0;
      margin: 0;
    }
    span {
      font-size: 12px;
      color: #646566;
    }
  }
  .van-cell__title,
  .van-cell__value {
    flex: none;
  }
  .van-cell__title {
    font-size: 14px;
    font-weight: 600;
  }
  .van-field__label {
    span {
      font-size: 16px;
      font-weight: 600;
    }
  }
  .van-cell {
    justify-content: space-between;
  }
  .content {
    font-size: 12px;
    text-indent: 2em;
    padding-bottom: 10px;
  }
  .img-box {
    display: flex;
    justify-content: space-around;
    margin-bottom: 10px;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
</style>